import os
import re
import pandas as pd

# 设置日志文件夹路径
log_folder = '../countlogs/'

# 创建一个空的DataFrame来存储结果
result_df = pd.DataFrame(columns=['Logfile', 'Formula', 'NumberofSchemas'])

# 遍历日志文件夹中的所有文件
for filename in os.listdir(log_folder):
    if filename.endswith('.log'):
        file_path = os.path.join(log_folder, filename)
        with open(file_path, 'r') as log_file:
            content = log_file.read()
            match = re.search(r'(\d+):.*?(\w+): (\d+) linear extensions to enumerate', content)
            if match:
                formula = match.group(2)
                log_name = filename.replace("count_schema_", "").replace(".log", "").replace(formula, "").replace(".ta_", "")
                schemas = match.group(3)
                result_df = result_df.append({'Logfile': log_name, 'Formula': formula, 'NumberofSchemas': schemas}, ignore_index=True)
            else:
                result_df = result_df.append({'Logfile': log_name, 'Formula': 'NaN', 'NumberofSchemas': 'Timeout'}, ignore_index=True)

# 按照Logfile字典序排序表格
result_df.sort_values(by='Logfile', inplace=True)

# 保存结果到CSV文件
result_df.to_csv('countlogs_result.csv', index=False)
print("处理完毕 结果已保存到result.csv文件中。")
